//
//	View.m
//	IconView
//
//	Created by David Thorpe on 03/12/2007.
//	Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "FontIconView.h"

@implementation FontIconView

@synthesize selected = m_isSelected;
@synthesize delegate = m_theDelegate;

-(id)copyWithZone:(NSZone *)zone {
	//NSLog(@"FontIconView.copyWithZone");
	FontIconView* theCopy = [[FontIconView allocWithZone:zone] initWithFrame:[self frame]];
	[theCopy setDelegate:[self delegate]];
	[theCopy setSelected:[self selected]];
	return theCopy;
}

//-(void)setSelected:(BOOL)flag {
//	m_isSelected = flag;
//}

//-(id)delegate {
//	return m_theDelegate;
//}
//
//-(void)setDelegate:(id)theDelegate {
//	m_theDelegate = theDelegate;
//}

//-(BOOL)selected {
//	return m_isSelected;
//}

-(void)drawRect:(NSRect)rect {
	//UKLog(@"FontIconView:drawRect");
	if([self selected]) {
		UKLog(@"selected");
		[[NSColor grayColor] set];
		NSFrameRect(NSInsetRect([self bounds], 1.0, 1.0));
	}
	[super drawRect:rect];
}

-(NSView *)hitTest:(NSPoint)aPoint {
	// don't allow any mouse clicks for subviews in this view

	NSRect Bounds = [self bounds];
	Bounds.origin.y += 17;
	Bounds.size.height -= 17;
	UKLog(@"point: %@, bounds: %@", NSStringFromPoint(aPoint), NSStringFromRect([self convertRect:Bounds toView:[self superview]]));
	
	if(NSPointInRect(aPoint,[self convertRect:Bounds toView:[self superview]])) {
		UKLog(@"hit:");
		return self;
	} else {
		return [super hitTest:aPoint];
	}
}

-(void)mouseDown:(NSEvent *)theEvent {
	[super mouseDown:theEvent];
	// check for click count above one
	if([theEvent clickCount] > 1) {
		NSLog(@"hittest:mouseDown");
		if([[self delegate] respondsToSelector:@selector(doubleClick:)]) {
			[[self delegate] doubleClick:self];
		}
	}
}
- (void)setFrame_:(NSRect)frameRect {
	if (frameRect.size.width < 100.0) {
		
		UKLog(@"frameRect: %@, %@", NSStringFromRect(Name.frame), NSStringFromRect(Unicode.frame));
	}
	
	[super setFrame:frameRect];
}
@end
